package com.zhaolulu.openai;

import com.openai.client.OpenAIClient;
import com.openai.client.okhttp.OpenAIOkHttpClient;
import com.openai.models.chat.completions.ChatCompletionCreateParams;

/**
 * @author zzj
 * @version 1.0
 */
public class CompletionsDemo {

    public static void main(String[] args) {
        //1. 创建客户端
        OpenAIClient client = OpenAIOkHttpClient.builder()
                .baseUrl("https://dashscope.aliyuncs.com/compatible-mode/v1")
                .apiKey(System.getenv("DASHSCOPE_API_KEY"))
                .build();

        //2. 构造请求参数
        ChatCompletionCreateParams createParams = ChatCompletionCreateParams.builder()
                // .model(ChatModel.GPT_3_5_TURBO)
//                .model("qwen-plus-2025-01-25")
                .model("qwen-plus")
                .addSystemMessage("你是一个java开发助手，名字叫作：林风")
                .addUserMessage("你是谁？")
                .build();

        //3. 通过客户端，发起请求
        client.chat().completions()
                .create(createParams)
                .choices()
                .stream()
                .flatMap(choice -> choice.message().content().stream())
                .forEach(System.out::println);
    }

}
